<?php
/**
 * Created by PhpStorm.
 * User: luanalex
 * Date: 2017/9/18
 * Time: 11:31
 */

?>

<html>
<head>
    <meta charset="UTF-8" />
    <title>菜鸟教程 React 实例</title>
    <script src="https://cdn.bootcss.com/react/15.4.2/react.min.js"></script>
    <script src="https://cdn.bootcss.com/react/15.4.2/react-dom.min.js"></script>
    <script src="https://cdn.bootcss.com/babel-standalone/6.22.1/babel.min.js"></script>
</head>
<body>
<div id="message" align="center" style="background-color: #2CB200"></div>

<script type="text/babel">
    var Counter = React.createClass({
        getInitialState: function () {
            return { clickCount: 0 };
        },
        handleClick: function () {
            this.setState(function(state) {
                return {clickCount: state.clickCount + 1};
            });
        },
        componentWillMount:function() {
            console.log('Component WILL MOUNT!')
        },
        componentDidMount:function() {
            console.log('Component DID MOUNT!')
        },
        componentWillReceiveProps:function(newProps) {
            console.log('Component WILL RECEIVE PROPS!')
        },
        shouldComponentUpdate:function(newProps, newState) {
            return true;
        },
        componentWillUpdate:function(nextProps, nextState) {
            console.log('Component WILL UPDATE!');
        },
        componentDidUpdate:function(prevProps, prevState) {
            console.log('Component DID UPDATE!')
        },
        componentWillUnmount:function() {
            console.log('Component WILL UNMOUNT!')
        },
        render: function () {
            return (<h2 onClick={this.handleClick}>点我！点击次数为: {this.state.clickCount}</h2>);
        }
    });
    ReactDOM.render(
    <Counter />,
        document.getElementById('message')
    );
</script>
</body>
</html>